<?php
$sn  = empty($_GET['sn']) ? 0 : trim($_GET['sn']);
if(empty($sn)){
	exit('参数丢失');
}
$oOrder = new Order();
$orderinfo = $oOrder->get_order_by_sn($sn, '*');

$statename = '';
$payment_statename = '';
$delivery_statename = '';
switch($orderinfo['state']){
	case '-2':
		$statename = '无效';
		break;
	case '-1':
		$statename = '已取消';
		break;
	case '0':
		$statename = '未确认';
		break;
	case '1':
		$statename = '已确认';
		break;
	case '2':
		$statename = '完成';
		break;
	case '3':
		$statename = '已评价';
		break;
}

switch($orderinfo['payment_state']){
	case '-1':
		$payment_statename = '付款失败';
		break;
	case '0':
		$payment_statename = '未付款';
		break;
	case '1':
		$payment_statename = '付款中';
		break;
	case '2':
		$payment_statename = '已付款';
		break;
}

switch($orderinfo['delivery_state']){
	case '0':
		$delivery_statename = '未发货';
		break;
	case '1':
		$delivery_statename = '配货中';
		break;
	case '2':
		$delivery_statename = '已发货';
		break;
	case '3':
		$delivery_statename = '已收货';
		break;
}
$orderinfo['statename'] = $statename;
$orderinfo['payment_statename'] = $payment_statename;
$orderinfo['delivery_statename'] = $delivery_statename;
$orderinfo['addtime'] = ftime($orderinfo['addtime']);
$orderinfo['confirm_time'] = $orderinfo['confirm_time'] > 0 ? ftime($orderinfo['confirm_time']) : '--';
$orderinfo['payment_time'] = $orderinfo['payment_time'] > 0 ? ftime($orderinfo['payment_time']) : '--';
$orderinfo['delivery_time'] = $orderinfo['delivery_state'] > 2 && $orderinfo['delivery_time'] > 0 ? ftime($orderinfo['delivery_time']) : '--';
$vars['orderinfo'] = $orderinfo;

// 收货人信息
$vars['addrinfo'] = $oOrder->get_order_address($sn, '*');

// 配送方式
$deliverys = cache_read('deliverys.php');
$vars['deliveryinfo'] = $deliverys[$orderinfo['delivery']];

// 支付方式
$payments = cache_read('payments.php');
$vars['paymentinfo'] = $payments[$orderinfo['payment']];

// 订单商品
$goodslist = $oOrder->get_order_goods_all($sn, $detail = true);
if(!empty($goodslist)){
	$vars['goodslist'] = array();
	foreach($goodslist as $goods){
		if(!empty($goods['goodsinfo']['filename'])){
			$goods['url'] = PUB_DIR.'goods/'.$goods['goodsinfo']['filename'].'.html';
		}else{
			$goods['url'] = PUB_DIR.'goods/'.time_to_path($goods['goodsinfo']['addtime']).'/'.$goods['goodsinfo']['id'].'.html';
		}
		$vars['goodslist'][] = $goods;
	}
	//$vars['goods_cost'] = $orderinfo['cost'];
	//$vars['goods_weight'] = $orderinfo['weight'];
}
?>